package com.qing.service.impl;

import com.qing.pojo.Document;
import com.qing.mapper.DocumentMapper;
import com.qing.service.DocumentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qing.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qinghua
 * @since 2022-06-06
 */
@Service
public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> implements DocumentService {

    @Autowired
    private FileUtil fileUtil;

    @Autowired
    private DocumentMapper mapper;

    @Override
    public Boolean upload(MultipartFile file,String title,String remake,Integer userId) {
        String filePath = fileUtil.upload(file);
        Document document = new Document();
        document.setTitle(title);
        document.setRemake(remake);
        document.setFileName(file.getOriginalFilename());
        document.setFilePath(filePath);
        document.setUserId(userId);
        return save(document);
    }

    @Override
    public List<Map<String, Object>> queryAllAndName() {
        return mapper.queryAllAndName();
    }

}
